<script type="text/javascript" language="javascript">
   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }
	
   function makeHTTPRequest(url) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = utilizador_handle;
      http_request.open('GET', url, true);
      //http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      //http_request.setRequestHeader("Content-length", parameters.length);
      //http_request.setRequestHeader("Connection", "close");
      http_request.send(null);
   }
   
   function utilizador_handle()
   {
   	if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            result = http_request.responseText;
            document.getElementById('login_client').innerHTML = result;
            tb_remove();
         }
      }
   }
   
   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            if(result.substring(0,2) != "OK")
            {
            	document.getElementById('resposta').innerHTML = result;
            } else {
            	makeHTTPRequest('/clientes/get_utilizador');
            }            
         } else {
            document.getElementById('resposta').innerHTML = 'There was a problem with the request.';
         }
      }
   }
   
   function get(obj) {
      var poststr = "utilizador=" + encodeURI( document.getElementById("utilizador").value ) +
                    "&password=" + encodeURI( document.getElementById("password").value );
      makePOSTRequest('/clientes/do_login', poststr);
   }
</script>
<a href='/utilizadores/registo'> Novo Utilizador </a> <br />
<div style="text-align: center; margin-top: 30px; margin-bottom: 10px;">
<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform">
 <LABEL for="utilizador"><?=IDIOMA_LOGIN_BOX_UTILIZADOR?>: </LABEL>
 <input type="text" id="utilizador" name="utilizador"></input><BR />
 <LABEL for="utilizador"><?=IDIOMA_LOGIN_BOX_PASSWORD?>: </LABEL>
 <input type="password" id="password" name="password"></input><BR />
 <p><input type="button" name="button" value="Submit" onclick="javascript:get(this.parentNode);"></p>
</form>
</div>
<div>
<font style="color: #FF0000">
<span name="resposta" id="resposta"></span>
</font>
</div>